//
//  MachineView.m
//  SmartCup
//
//  Created by Kendama on 2017/5/19.
//  Copyright © 2017年 DT. All rights reserved.
//

#import "MachineView.h"

@implementation MachineView

- (instancetype)init{
    
    if ([super init]) {
        
        self.backgroundColor = [UIColor whiteColor];
        [self masLayoutSubview];
        
    }
    
    return self;
    
}

- (void)masLayoutSubview{
    [self.topImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self);
        make.width.equalTo(self);
        make.height.mas_equalTo(px1920Height(548));
    }];
    
    [self.topView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.topImageView.mas_bottom);
        make.width.equalTo(self);
        make.height.mas_equalTo(px1920Height(192));
    }];
    
    
    [self.iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.topView);
        make.left.mas_equalTo(px1080Width(48));
        make.width.mas_equalTo(px1080Width(256));
        make.height.mas_equalTo(px1920Height(60));
    }];
    
    [self.line1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.topView);
        make.left.equalTo(self.iconImageView.mas_right).with.offset(px1080Width(34));
        make.right.equalTo(self.topView);
        make.height.mas_equalTo(1);
    }];
    
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.topView).with.offset(px1920Height(23));
        make.left.equalTo(self.line1);
        make.right.equalTo(self.topView);
        make.height.mas_equalTo(px1920Height(50));
    }];
    
    [self.line2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.topView);
        make.width.equalTo(self.topView);
        make.height.mas_equalTo(1);
    }];
    
    [self.numberLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.line1).with.offset(px1920Height(23));
        make.left.equalTo(self.line1);
        make.right.equalTo(self.topView);
        make.height.mas_equalTo(px1920Height(50));
    }];
}

- (void)setDevice:(DTCDeviceModel *)device {
    _device = device;
    NSString *string = device.localName;
    string = [string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
    _nameLabel.text = [NSString stringWithFormat:@"产品名称：【%@】",string];
    _numberLabel.text = [NSString stringWithFormat:@"设备序列号：%@",device.mac];
}

#pragma mark -- 懒加载
- (UIImageView *)topImageView
{
    if(!_topImageView)
    {
        __weak UIView *superView = self;
        _topImageView = [[UIImageView alloc]init];
        [superView addSubview:_topImageView];
        _topImageView.image = [UIImage imageNamed:@"bg_baner"];
    }
    return _topImageView;
}

- (UIView *)topView
{
    if(!_topView)
    {
        __weak UIView *superView = self;
        _topView = [[UIView alloc]init];
        _topView.backgroundColor = [UIColor whiteColor];
        [superView addSubview:_topView];
    }
    return _topView;
}


- (UIView *)line1
{
    if(!_line1)
    {
        __weak UIView *superView = self.topView;
        _line1 = [[UIView alloc]init];
        _line1.backgroundColor = [UIColor colorWithHexString:@"#D0D3DC"];
        [superView addSubview:_line1];
    }
    return _line1;
}


- (UIView *)line2
{
    if(!_line2)
    {
        __weak UIView *superView = self.topView;
        _line2 = [[UIView alloc]init];
        _line2.backgroundColor = [UIColor colorWithHexString:@"#D0D3DC"];
        [superView addSubview:_line2];
    }
    return _line2;
}



- (UIImageView *)iconImageView
{
    if(!_iconImageView)
    {
        __weak UIView *superView = self.topView;
        _iconImageView = [[UIImageView alloc]init];
        [superView addSubview:_iconImageView];
        _iconImageView.image = [UIImage imageNamed:@"home_logo"];
    }
    return _iconImageView;
}

- (UILabel *)nameLabel
{
    if(!_nameLabel)
    {
        __weak UIView *superView = self.topView;
        _nameLabel = [[UILabel alloc]init];
        [superView addSubview:_nameLabel];
        [_nameLabel setFont:[UIFont systemFontOfSize:15]];
        [_nameLabel setTextColor:[UIColor colorWithHexString:@"#585D6D"]];
        _nameLabel.text = @"产品名称：【一杯子】";
    }
    return _nameLabel;
}
- (UILabel *)numberLabel
{
    if(!_numberLabel)
    {
        __weak UIView *superView = self.topView;
        _numberLabel = [[UILabel alloc]init];
        [superView addSubview:_numberLabel];
        [_numberLabel setFont:[UIFont systemFontOfSize:15]];
        [_numberLabel setTextColor:[UIColor colorWithHexString:@"#585D6D"]];
        _numberLabel.text = @"设备序列号：07551314520";
    }
    return _numberLabel;
}

@end
